package day07;

public class 解码方法 {
    public int numDecodings(String ss) {
        // 转换为字符数组
        char[] s = ss.toCharArray();
        int n = s.length;
        int[] dp = new int[n + 1];
        // 初始化
        dp[0] = 1;
        for (int i = 1; i <= n; i++) {
            if (s[i - 1] != '0') {
                dp[i] += dp[i - 1];
            }
            if (i >= 2) {
                int num = (s[i - 2] - '0') * 10 + (s[i - 1] - '0');
                if (num >= 10 && num <= 26) {
                    dp[i] += dp[i - 2];
                }
            }
        }
        return dp[n];
    }
}
